import { BaseWindow } from "../../../../component/window/BaseWindow";
import { ILayer } from "../../../../mvc/interfaces/ILayer";
import { Language } from "../../../../../extend/language/Language";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { Cache } from "../../../cache/Cache";
import { PetExploreConfig } from "../../../resource/PetExploreConfig";
import { GameConst } from "../../../../component/gconst/GameConst";
import { PetExploreUtil } from "./info/PetExploreUtil";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
//class PetExploreAgainWindow
    
    export  class PetExploreAgainWindow extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this.setSize(310, 205);
            this.titleHeight = 28;
            this.title = Language.getString(54584);
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            ObjCreate.createBg(17, 39, 275, 155, this);
            this._failureTxt = ObjCreate.createTextField("", 40, 50, 220, 20, this);
            this._leftTxt = ObjCreate.createTextField("", 40, 80, 220, 20, this);
            this._costTxt = ObjCreate.createTextField("", 40, 100, 220, 20, this);
            this._coinBitmap = ObjCreate.createBitmap(ImagesConst.Tongqian_bind, 150, 98, this);
            ObjCreate.createTextField(Language.getString(54587), 40, 130, 220, 20, this, GlobalStyle.textFormat6);
            this._continueBtn = ObjCreate.createGButton(Language.getString(54588), 50, 160, 70, 28, this);
            this._continueBtn.name = "continue";
            this._laterBtn = ObjCreate.createGButton(Language.getString(54589), 185, 160, 70, 28, this);
            this._continueBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnClickHandler);
            this._laterBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnClickHandler);
            return;
        }

        public updateInfo(): void
        {
            var loc2=null;
            var loc3=0;
            var loc1=Cache.instance.petExplore.petExploreInfo;
            if (loc1) 
            {
                loc3 = loc1.currentLevel != 0 ? loc1.currentLevel : 1;
                loc2 = PetExploreConfig.instance.getExploreConfigByLevel(loc3);
            }
            if (loc2) 
            {
                this._failureTxt.htmlText = Language.getStringByParam(54590, loc2.name);
                this._leftTxt.htmlText = Language.getStringByParam(54585, GameConst.PetExploreMaxTimesPerDay - loc1.times);
                this._costTxt.htmlText = Language.getStringByParam(54586, PetExploreUtil.getAgainExploreCost(loc1.times));
                this._coinBitmap.x = this._costTxt.x + this._costTxt.textWidth + 5;
            }
            return;
        }

        /* internal  */onBtnClickHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc2=null;
            var loc3=null;
            var loc4=0;
            var loc1=(arg1.target as GButton).name;
            if (loc1 != "continue") 
            {
                this.hide();
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetExploreBattleWindowClose));
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetExploreOpen, false));
            }
            else 
            {
                loc2 = Cache.instance.petExplore.petExploreInfo;
                if (loc2) 
                {
                    loc4 = loc2.currentLevel != 0 ? loc2.currentLevel : 1;
                    loc3 = PetExploreConfig.instance.getExploreConfigByLevel(loc4);
                }
                if (loc3) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PetExploreAgainStart, loc3));
                }
            }
            return;
        }

        /* internal */ /* var */_failureTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_leftTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_costTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_coinBitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_continueBtn: GButton;

        /* internal */ /* var */_laterBtn: GButton;
    }
